package com.race;

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Killer {

    public static void main(String[] args) {
        // write your code here

        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();

        List<Integer> list = new LinkedList<>();

        for (int i = 0; i < m; i++) {
            list.add(i + 1);
        }


        int result = doNext(list, n);

        System.out.println("result=" + result);
    }

    private static int doNext(List<Integer> list, int n) {
        if (list.size() == 1) return list.get(0);

        int k = 0;

        int length = list.size();
        if (length >= n) {
            list.remove(n - 1);
        } else {
            int i = 2;
            int total = i * length;
            while (true) {
                if (total >= n) {
                    break;
                }
                total = (i++) * length;
            }

            int index = total - n;
            k = length - index;
        }

        list.remove(k);

        return doNext(list, n);
    }

    private static int select(int m, int n) {
        if (m == n) return n;
        int t = select(m - m / n, n);
        return t + (t - 1) / (m - 1);
    }

    static class Node {
        Node pre;
        Node next;
        int value;

        Node(Node pre, Node next, int value) {
            pre = pre;
            next = next;
            value = value;
        }
    }

}
